//
//  TrueNameViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/10/17.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "TrueNameViewController.h"
#import "RegisterVIew.h"
#import "JTCSM.h"
#import "NetworkRequest.h"
#import "ImageModel.h"
#import "UIImageView+addTag.h"
#import "GetInfoClass.h"
#import "MyInfoView.h"
#import "AddressPickerView.h"
#import "KaiHuHangViewController.h"
#define KTop 10
#define KWidthOfRegister 40
#define KImageSize  15
@interface TrueNameViewController ()<UITextFieldDelegate,UIAlertViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,AddressPickerViewDelegate,KaiHuHangViewControllerDelegate>

{
    NSArray *imageNameArray;
    NSArray *placeholderArray;
    NSString *name ;
    NSString *idCard ;
    NSString *bankCard ;
    NSString *bankName ;
    NSString *phoneNumber ;
    NSString *code ;
    NSString *shopname ;
    NSString *shopaddress ;
    NSString *shopinfonews ;
    NSMutableArray* _areaArray;
    RegisterVIew * registerV;
    UIButton *getKeyBtn;
    NSTimer* _timer1;
    NSTimer* _timer2;
    NSInteger count ;
    UIButton *radioBtn;
    BOOL isSelector;
    NSMutableArray *textFieldArray;
    int idx ;
    UIScrollView *backView ;
    
    UIImageView *choice1ImageV;
    UIImageView *choice2ImageV;
    UIImageView *choice3ImageV;
    UIImageView *choice4ImageV;

    ImageModel *imageM;
    NSMutableDictionary *imageModelDict;
    NSArray *imageArray;
    
    RegisterVIew *searchoneview;
    RegisterVIew *searchtwoview;
    
    NSString *shengstring;
    NSString *citystring;
    NSString *bankcode;
    NSString *truebank;
    
    UITextField *beginTextfield;
}

@property (nonatomic ,strong) AddressPickerView * pickerView;

@end

@implementation TrueNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.view.backgroundColor =[UIColor whiteColor];
    self.navigationController.navigationBar.hidden = NO;
    textFieldArray = [NSMutableArray arrayWithCapacity:2];
    //设置barbuttonitem
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    
    self.navigationItem.rightBarButtonItem = [leftbtn setBarButtonItemsTitle:@"提交" frame:KRightBarButtonItemFrame_text target:self SEL:@selector(tijiao)];

    //回收键盘
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeKeyBoard)];
    [self.view addGestureRecognizer:tap];
    
    imageModelDict = [NSMutableDictionary dictionaryWithCapacity:2];
    [self aboutDataArray];
    [self layoutView];
    [self.view addSubview:self.pickerView];
    // Do any additional setup after loading the view.
}
- (void)gotBack{
    
    //    self.navigationController.navigationBar.hidden = YES;
    
    [self.navigationController popViewControllerAnimated:YES];
//    [df gotoLoginVC:self.navigationController];
}

- (void)tijiao{
    
//    UIImageView *imageone = (UIImageView *)[self.view viewWithTag:20000];
//    UIImageView *imagetwo = (UIImageView *)[self.view viewWithTag:20001];
//    UIImageView *imagethree = (UIImageView *)[self.view viewWithTag:20002];
//    UIImageView *imagefour = (UIImageView *)[self.view viewWithTag:20003];
    
    if ([bankcode isEqualToString:@""]) {
        [df showAlertWithTitle:@"您选择手动开户行，您的实名信息将有工作人员进行审核！" message:nil btn1:@"确认提交" btn2:@"继续完善 " btn3:nil delegate:self tag:19];
        
    }else{
        [self tijiaosure];
    }
    
    
    

}
- (void)tijiaosure{
    LoadData *request = [[LoadData alloc]init];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:2];
    [dict setObject:KTokenString forKey:@"token"];
    [dict setObject:name==nil?@"":name forKey:@"truename"];
    [dict setObject:idCard==nil?@"":idCard forKey:@"id_card"];
    [dict setObject:bankCard==nil?@"":bankCard forKey:@"bank_card"];
    [dict setObject:bankName==nil?@"":bankName forKey:@"bank_name"];
    [dict setObject:phoneNumber==nil?@"":phoneNumber forKey:@"bank_tel"];
    [dict setObject:shopname==nil?@"":shopname forKey:@"merch_name"];
    [dict setObject:shopinfonews==nil?@"":shopinfonews forKey:@"merch_door"];
    [dict setObject:truebank==nil?@"":truebank forKey:@"truebank"];
    [dict setObject:bankcode==nil?@"":bankcode forKey:@"bankcode"];
    [dict setObject:bankName==nil?@"":bankName forKey:@"bank"];
    [dict setObject:code==nil?@"":code forKey:@"code"];
    [dict setObject:choice1ImageV.tagKey==nil?@"":choice1ImageV.tagKey forKey:@"img_positive"];
    [dict setObject:choice2ImageV.tagKey==nil?@"":choice2ImageV.tagKey forKey:@"img_negative"];
    [dict setObject:choice3ImageV.tagKey==nil?@"":choice3ImageV.tagKey forKey:@"img_person"];
    [dict setObject:choice4ImageV.tagKey==nil?@"":choice4ImageV.tagKey forKey:@"img_bank"];
    
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"User/verified") withDict:dict superView:self.view isAddtag:NO Block:^(id result) {
         
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
            [df showAlertWithTitle:[result objectForKey:@"msg"] message:nil btn1:@"返回" btn2:nil btn3:nil delegate:self tag:13];
        }else{
            [df showAlertWithTitle:[result objectForKey:@"msg"] message:nil btn1:@"返回" btn2:nil btn3:nil delegate:nil tag:0];
        }
        
    }];
}



- (void)layoutView{
    
   
    
    backView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight)];
    backView.userInteractionEnabled = YES;
    [self.view addSubview:backView];
    
    MyInfoView *oneview = [[MyInfoView alloc]initWithFrame:CGRectMake(0, 10, KCONTROLLERWith-20, KWidthOfRegister) imagename:@"shopimage.png" title:@"商户信息" placeholder:nil isShowLabel:labelType radioBtnIndex:0 GroupId:nil];
    [backView addSubview:oneview];
    
    idx = 0;
    placeholderArray=@[@"输入商户名称",@"请选择",@"详细门牌号"];
    for (int i = 0; i < placeholderArray.count; i++) {
        registerV = [[RegisterVIew alloc]initWithFrame:CGRectMake(-20,KVIEW_Y(oneview)+i*(KWidthOfRegister+10), self.view.frame.size.width, KWidthOfRegister) labeTtext:nil placeholder:placeholderArray[i]];
        registerV.userInteractionEnabled =YES;
        registerV.textField.delegate = self;
        registerV.textField.tag = 200+i;
        registerV.tag = 2000+i;
        [registerV.textField setValue:RGBACOLOR(120, 130, 140,1) forKeyPath:@"_placeholderLabel.textColor"];
        [backView addSubview:registerV];
        [textFieldArray addObject:registerV];
        [self addImageWith:registerV];
        [self addLineWith:registerV];
        if (i == 1) {
            registerV.textField.enabled = NO;
        }
        
    }

    
    MyInfoView *twoview = [[MyInfoView alloc]initWithFrame:CGRectMake(0, KVIEW_Y(registerV), KCONTROLLERWith-20, KWidthOfRegister) imagename:@"infoimage.png" title:@"个人信息"placeholder:nil isShowLabel:labelType radioBtnIndex:0 GroupId:nil];
    [backView addSubview:twoview];

    placeholderArray=@[@"输入真实姓名",@"输入身份证号",@"输入储蓄卡号",@"请选择",@"请选择",@"输入手机号码",@""];
    for (int i = 0; i < placeholderArray.count; i++) {
        registerV = [[RegisterVIew alloc]initWithFrame:CGRectMake(-20,10+KVIEW_Y(twoview) +i*(KWidthOfRegister+10), self.view.frame.size.width, KWidthOfRegister) labeTtext:nil placeholder:placeholderArray[i]];
        registerV.userInteractionEnabled =YES;
        registerV.textField.delegate = self;
        registerV.textField.tag = 100+i;
        registerV.tag = 1000+i;
        [registerV.textField setValue:RGBACOLOR(120, 130, 140,1) forKeyPath:@"_placeholderLabel.textColor"];
//        registerV.label.textAlignment = NSTextAlignmentLeft;
        [backView addSubview:registerV];
        [textFieldArray addObject:registerV];
        [self addImageWith:registerV];
        [self addLineWith:registerV];
        if (i == 3 || i==4) {
            
            registerV.textField.enabled = NO;
            UIImageView *imageView  = [[UIImageView alloc]initWithFrame:CGRectMake(KCONTROLLERWith-KImageSize-13, registerV.frame.origin.y+(registerV.frame.size.height-KImageSize)/2, KImageSize, KImageSize)];
            imageView.image = [UIImage imageNamed:@"myFanhui.png"];
            [backView addSubview:imageView];
            
            [df addTapGestureRecognizerWithTarget:self action:@selector(search:) andaddView:registerV];
        }
        
        if (i ==placeholderArray.count-1) {
            getKeyBtn = [UIButton initWithFrame:CGRectMake(KCONTROLLERWith-KBtnWidth-13, registerV.frame.origin.y, KBtnWidth-5, 30) backgrandColor:RGBACOLOR(0, 145, 255, 1 ) titleColor:[UIColor whiteColor] title:@"获取验证码" titleFont:12];
            [getKeyBtn addTarget:self action:@selector(getToKey) forControlEvents:UIControlEventTouchUpInside];
            [backView addSubview:getKeyBtn];
            
            registerV.textField.frame = CGRectMake(registerV.textField.frame.origin.x, registerV.textField.frame.origin.y, registerV.textField.frame.size.width-KBtnWidth-10, registerV.textField.frame.size.height);
            [df layerWithView:getKeyBtn radius:4 width:0 color:nil];
        }
        
    }
//    173/97
    CGFloat spaceofLeft = 20;
    CGFloat spaceofTop = 13;
    CGFloat space = 10;
    CGFloat imageWidth = (KCONTROLLERWith-2*spaceofLeft-space)/2;
    imageArray = @[@"idcard_zheng",@"idcard_fan",@"bankcard_zheng",@"bankcard_fan"];
    for (int i = 0; i < imageArray.count; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(spaceofLeft + (space+imageWidth)*(i%2), KVIEW_Y(registerV)+20+(imageWidth*97/173+spaceofTop)*(i/2), imageWidth, imageWidth*97/173)];
        imageView.image = [UIImage imageNamed:imageArray[i]];
        imageView.tag = 20000+i;
        (i == 0?(choice1ImageV = imageView):(i==1?choice2ImageV = imageView:(i==2?choice3ImageV = imageView:(choice4ImageV = imageView))));
        imageView.userInteractionEnabled = YES;
        [df addTapGestureRecognizerWithTarget:self action:@selector(choiceImage:) andaddView:imageView];
        [backView addSubview:imageView];
        [backView setContentSize: CGSizeMake(self.view.frame.size.width, KVIEW_Y(imageView)+20)];
    }
    
    
    RegisterVIew *view0 = [self.view viewWithTag:1000];
    RegisterVIew *view1 = [self.view viewWithTag:1001];
    RegisterVIew *view2 = [self.view viewWithTag:1002];
    RegisterVIew *view3 = [self.view viewWithTag:1003];
    RegisterVIew *view4 = [self.view viewWithTag:1004];
    RegisterVIew *view5 = [self.view viewWithTag:1005];
    
    RegisterVIew *view00 = [self.view viewWithTag:2000];
    RegisterVIew *view01 = [self.view viewWithTag:2001];
    RegisterVIew *view02 = [self.view viewWithTag:2002];
    
    
    [[GetInfoClass shareSingle] getinfo];
    [GetInfoClass shareSingle].myblock = ^(UserInfoModel *Model) {
        
        view01.textField.text = [NSString stringWithFormat:@"%@",Model.merch_address];
        if (Model.truename != nil && ![Model.truename isEqualToString:@""]) {
            if (![Model.reason isEqualToString:@""]&&Model.reason!=nil) {
                [df showAlertWithTitle:Model.reason message:nil btn1:@"知道了" btn2:nil btn3:nil delegate:nil tag:0];
            }
            view00.textField.text = Model.merch_name;
            view02.textField.text = Model.merch_door;
            view0.textField.text = Model.truename;
            name = Model.truename;
            view1.textField.text = Model.id_card;
            idCard = Model.id_card;
            view2.textField.text = Model.bank_card;
            bankCard = Model.bank_card;
            view3.textField.text = @"";
            view4.textField.text = @"";
            bankName = Model.bank_name;
            view5.textField.text = Model.bank_tel;
            phoneNumber = Model.bank_tel;
            [choice1ImageV sd_setImageWithURL:[NSURL URLWithString:Model.positive_path] placeholderImage:[UIImage imageNamed:@"idcard_zheng"]];
            choice1ImageV.tagKey = Model.img_positive;
            [choice2ImageV sd_setImageWithURL:[NSURL URLWithString:Model.negative_path] placeholderImage:[UIImage imageNamed:@"idcard_fan"]];
            choice2ImageV.tagKey = Model.img_negative;

            [choice3ImageV sd_setImageWithURL:[NSURL URLWithString:Model.person_path] placeholderImage:[UIImage imageNamed:@"bankcard_zheng"]];
            choice3ImageV.tagKey = Model.img_person;

            [choice4ImageV sd_setImageWithURL:[NSURL URLWithString:Model.bank_path] placeholderImage:[UIImage imageNamed:@"bankcard_fan"]];
            choice4ImageV.tagKey = Model.img_bank;

        }
        
        
        
    };
    
}
#pragma mark 选择开户地址 和银行
- (void)search:(UITapGestureRecognizer *)tap{
    [beginTextfield resignFirstResponder];
    RegisterVIew *view = (RegisterVIew *)[tap view];
    if (view.tag == 1003) {
        searchoneview = view;
       [self.pickerView show];
    }
    if (view.tag == 1004) {
        searchtwoview = view;
        
        if (bankName == nil || [bankName isEqualToString:@""] ||bankCard == nil || [bankCard isEqualToString:@""]) {
            [df showAlertWithTitle:@"请输入正确的卡号" message:nil btn1:@"知道了" btn2:nil btn3:nil delegate:nil tag:0];
            return;
        }

        if (citystring == nil || [citystring isEqualToString:@""] ||shengstring == nil || [shengstring isEqualToString:@""]) {
            [df showAlertWithTitle:@"请选择开户地址" message:nil btn1:@"知道了" btn2:nil btn3:nil delegate:nil tag:0];
            return;
        }
        
        KaiHuHangViewController *vc = [[KaiHuHangViewController alloc]init];
        vc.nameTitle = @"开户行";
        vc.bank_name = bankName;
        vc.bank_card = bankCard;
        vc.province = shengstring;
        vc.city = citystring;
        vc.delegate = self;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}

- (void)getBankKaiHuHang:(NSString *)kaihuhang kaihu_id:(NSString *)kaihuid{
    searchtwoview.textField.text = kaihuhang;
    truebank = kaihuhang;
    bankcode = kaihuid;
}

- (void)choiceImage:(UITapGestureRecognizer *)tap{
    //先设定sourceType为相机，然后判断相机是否可用（ipod）没相机，不可用将sourceType设定为相片库
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];//初始化
    picker.delegate = self;
    picker.view.tag = tap.view.tag;
    picker.allowsEditing = YES;//设置可编辑
    picker.sourceType = sourceType;
    [self presentViewController:picker animated:YES completion:^{
    }];//进入照相界面

//    [df showAlertWithTitle:@"请选择" message:nil btn1:@"取消" btn2:@"相机" btn3:@"相册" delegate:self tag:12];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//    if (alertView.tag == KAlertVTag+12) {
//        if (buttonIndex == 1) {
//                    }
//        if (buttonIndex == 2) {
//           
//           UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//           UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
//           pickerImage.sourceType = sourceType;
//           pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];
//           pickerImage.delegate = self;
//           pickerImage.allowsEditing = NO;
//           [self presentViewController:pickerImage animated:YES completion:^{
//               
//           }];
//                
//            
//
//        }
//        
//    }
    
    if (alertView.tag == KAlertVTag+13) {
        [self gotBack];
    }
    if(alertView.tag == KAlertVTag+19){
        
        if (buttonIndex == 0) {
             [self tijiaosure];
        }
    }

}

//点击相册中的图片 货照相机照完后点击use  后触发的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
    
    //当选择的类型是图片
    if ([type isEqualToString:@"public.image"])
    {
//        //先把图片转成NSData
        UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        if (picker.view.tag == 20000) {
            choice1ImageV.image = image;
            [df showWaiting:choice1ImageV];
        }
        if (picker.view.tag == 20001) {
            choice2ImageV.image = image;
            [df showWaiting:choice2ImageV];
        }
        if (picker.view.tag == 20002) {
            choice3ImageV.image = image;
            [df showWaiting:choice3ImageV];
        }
        if (picker.view.tag == 20003) {
            choice4ImageV.image = image;
            [df showWaiting:choice4ImageV];
        }
        NetworkRequest *r = [[NetworkRequest alloc]init];
        [r postImageToserverWithURL:KURLPOSTHeadr(@"User/uploadCard") object:info resultBlock:^(id data) {
            
            if ([[df getString:KDataOfKey(@"status")] isEqualToString:@"1"]) {
                imageM = [[ImageModel alloc]init];
                [imageM setValuesForKeysWithDictionary:KDataOfKey(@"data")];
                
//                [imageModelDict setObject:imageM forKey:choiceImageV.tagKey];
                if (picker.view.tag == 20000) {
                    choice1ImageV.tagKey = imageM.fileid;
                }
                if (picker.view.tag == 20001) {
                    choice2ImageV.tagKey = imageM.fileid;
                }
                if (picker.view.tag == 20002) {
                    choice3ImageV.tagKey = imageM.fileid;
                }
                if (picker.view.tag == 20003) {
                    choice4ImageV.tagKey = imageM.fileid;
                }


//                [choiceImageV sd_setImageWithURL:[NSURL URLWithString:imageM.filepath]];
            }else{
                [df showAlertWithTitle:@"图片上传失败" message:nil btn1:@"知道了" btn2:nil btn3:nil delegate:self tag:0];
                choice1ImageV.image = imageArray[choice1ImageV.tag-20000];
                choice2ImageV.image = imageArray[choice2ImageV.tag-20001];
                choice3ImageV.image = imageArray[choice3ImageV.tag-20002];
                choice4ImageV.image = imageArray[choice4ImageV.tag-20003];
            }
            
            if (picker.view.tag == 20000) {
                [df hideWaiting:choice1ImageV];            }
            if (picker.view.tag == 20001) {
                [df hideWaiting:choice2ImageV];            }
            if (picker.view.tag == 20002) {
                [df hideWaiting:choice3ImageV];            }
            if (picker.view.tag == 20003) {
                [df hideWaiting:choice4ImageV];            }


        }];
        
        [picker dismissViewControllerAnimated:YES completion:^{
            
        }];
    }
}

//点击cancel 调用的方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    
    
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark --添加灰线条
-(void)addImageWith:(UIView *)fatherview{
    
    UILabel *lable =[[UILabel alloc] initWithFrame:CGRectMake(40,  0, 120, KWidthOfRegister)];
    [lable setText:imageNameArray[idx++]];
    lable.textAlignment=NSTextAlignmentLeft;
    lable.backgroundColor =[UIColor whiteColor];
    //imageView.image=[UIImage imageNamed:imageNameArray[idx++]];
    lable.font =[UIFont fontWithName:@"Arial" size:15.0];
    [fatherview addSubview:lable];
    
    
}
- (void)addLineWith:(UIView *)fatherview{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, fatherview.frame.size.height-1, KCONTROLLERWith+100, 1.5)];
    view.backgroundColor = RGBACOLOR(226, 227, 228,1);
    [fatherview addSubview:view];
    
}

- (void)getKeyboardPodWithTextfield:(UITextField *)textfield{
//    if (textfield.tag == 100 || textfield.tag == 101 ) {
//        textfield.keyboardType = UIKeyboardTypePhonePad;
//    }
    //    if (textfield.tag == 101||textfield.tag == 102) {
    //        textfield.secureTextEntry = YES;
    //    }
    
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    
    if (textField.tag == 100) {
        name = textField.text;
    }
    if (textField.tag == 101) {
        idCard = textField.text;
    }
    if (textField.tag == 102) {
        bankCard = textField.text;
    }
    if (textField.tag == 105) {
        phoneNumber = textField.text;
    }
    if (textField.tag == 106) {
        code = textField.text;
    }
    if (textField.tag == 200) {
        shopname = textField.text;
    }

    if (textField.tag == 201) {
        shopaddress = textField.text;
    }
    if (textField.tag == 202) {
        shopinfonews = textField.text;
    }

    
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder] ;
    return YES;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    beginTextfield = textField;
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容

    if (textField.tag == 102) {
        if ([toBeString length] > 15) {
            [self therequestwithBankNumber:toBeString];
        }

    }
    
    return YES;
}
- (void)removeKeyBoard{
    [self.view endEditing:YES];
}
- (void)aboutDataArray{
    
    imageNameArray =@[@"商户名称",@"经营地址",@"门牌号（选填）",@"真实姓名",@"身份证号",@"储蓄卡号",@"开户地址",@"开户银行",@"手机号码",@"验证码"];
    
    
}
#pragma mark --重新获取验证码
- (void)getTheCode{
    [self.view endEditing:YES];
    
    LoadData *request = [[LoadData alloc]init];
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:2];
    [dict setObject:@"verified" forKey:@"do"];
    NSLog(@"%@",phoneNumber);
    [dict setObject:phoneNumber==nil?@"":phoneNumber forKey:@"mobile"];
    [dict setObject:KTokenString forKey:@"token"];
    
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"User/smsverified") withDict:dict superView:self.view isAddtag:NO Block:^(id result) {
        
        [self gettime];
        
        NSLog(@"*********************%@",result);
        if (result == nil ) {
            [df showAlertWithTitle:@"获取验证码失败" message:nil btn1:@"返回" btn2:nil btn3:nil delegate:nil tag:0];
            return ;
        }
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            [df showAlertWithTitle:[result objectForKey:@"msg"] message:nil btn1:@"返回" btn2:nil btn3:nil delegate:nil tag:0];
        }else{
            [df showAlertWithTitle:[result objectForKey:@"msg"] message:nil btn1:@"返回" btn2:nil btn3:nil delegate:nil tag:0];
        }
        [getKeyBtn setTitle:@"获取验证码" forState:UIControlStateNormal];
        
    }];
    
    
}
- (void)getToKey{
    
    [self getTheCode];
    
}
#pragma mark --定时器
- (void)gettime{
    [_timer2 invalidate];
    [_timer1 invalidate];
    
    count = 0;
    
    NSTimer* timer=[NSTimer scheduledTimerWithTimeInterval:60
                                                    target:self
                                                  selector:@selector(showRepeatButton)
                                                  userInfo:nil
                                                   repeats:YES];
    
    NSTimer* timer2=[NSTimer scheduledTimerWithTimeInterval:1
                                                     target:self
                                                   selector:@selector(updateTime)
                                                   userInfo:nil
                                                    repeats:YES];
    _timer1=timer;
    _timer2=timer2;
    
}
-(void)updateTime{
    count++;
    if (count>60)
    {
        [_timer2 invalidate];
        return;
    }
    NSString *timeStr=[NSString stringWithFormat:@"%lus重新获取",(long)60-count];
    [getKeyBtn setTitle:timeStr forState:UIControlStateNormal];
    if(count == 60){
        [getKeyBtn setTitle:@"重新获取" forState:UIControlStateNormal];
    }
    
}
-(void)showRepeatButton{
    
    [_timer1 invalidate];
    return;
}


- (void)therequestwithBankNumber:(NSString *)bankNum{
    LoadData *request = [[LoadData alloc]init];
    [request loadDataPostAsynchronousWithURL:KURLPOSTHeadr(@"User/getBankInfo") withDict:@{@"token":KTokenString,@"bank_card":bankNum} superView:self.view isAddtag:NO  Block:^(id result) {
        
        NSString *isreturn = [NSString stringWithFormat:@"%@",[result objectForKey:@"status"]];
        if ([isreturn isEqualToString:@"1"]) {
            
            NSDictionary *dict = KResultOfKey(@"data");
            bankName = [dict objectForKey:@"bank_name"];
            
        }
    }];
    
}


- (AddressPickerView *)pickerView{
    if (!_pickerView) {
        _pickerView = [[AddressPickerView alloc]initWithFrame:CGRectMake(0, KCONTROLLERHeight , KCONTROLLERWith, 215)];
        _pickerView.delegate = self;
        // 关闭默认支持打开上次的结果
        //        _pickerView.isAutoOpenLast = NO;
    }
    return _pickerView;
}


#pragma mark - AddressPickerViewDelegate
- (void)cancelBtnClick{
    [self.pickerView hide];
}
- (void)sureBtnClickReturnProvince:(NSString *)province City:(NSString *)city Area:(NSString *)area{
    shengstring = province;
    citystring = city;
   [self.pickerView hide];
    searchoneview.textField.text = [NSString stringWithFormat:@"%@-%@",province,city];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//键盘回收
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    [beginTextfield resignFirstResponder];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
